﻿@using System.Collections.Specialized;
@using System.Security;
@using System.Text;
@using System.Web.WebPages.Scope;

@functions {

    public enum DisplayType { random, latest };
    public enum SizeType { Square, Thumb, MidSize };
    public enum SourceType { user, group, user_set, user_tag, all, all_tag }

    internal static string GetSizeString(SizeType sizeType)
    {
        string size = (sizeType == SizeType.Square) ? "s" : (sizeType == SizeType.Thumb) ? "t" : "m";
        return size;
    }

    internal static string GetSourceQueryString(SourceType sourceType, string flickrId, string tag)
    {
        string queryString = "source=" + sourceType;
        switch (sourceType)
        {
            case SourceType.all:
                break;
            case SourceType.all_tag:
                queryString += "&amp;tag=" + tag;
                break;
            case SourceType.group:
                queryString += "&amp;group=" + flickrId;
                break;
            case SourceType.user:
                queryString += "&amp;user=" + flickrId;
                break;
            case SourceType.user_set:
                queryString += "&amp;set=" + flickrId;
                break;
            case SourceType.user_tag:
                queryString += "&amp;user=" + flickrId + "&amp;tag=" + tag;
                break;
        }

        return queryString;
    }   
}

@*Razor helper to display Flickr Badge. 
count - number of images displayed. Max - 10
display - Random or Latest
size - Image size
source - user, group, user set, user and tag, all, tag
flickrId - user id, group id or user set id depending on Source
tag - image tag. Applied only for user_tag or all_tag sources
*@
@helper ShowBadge(int count = 10, DisplayType display = DisplayType.random, SizeType size = SizeType.Square, SourceType source = SourceType.all, string flickrId = "", string tag = "")
{   
    <script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?layout=x&amp;count=@count&amp;display=@display&amp;size=@GetSizeString(size)&amp;@GetSourceQueryString(source, flickrId, tag)"></script>
}
